package jsu.xxy.coffee3.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jsu.xxy.coffee3.domain.Product;
import jsu.xxy.coffee3.domain.ProductMaterial;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author 张从轩
* @description 针对表【product(商品信息表)】的数据库操作Mapper
* @createDate 2023-06-03 06:28:03
* @Entity jsu.xxy.coffee3.domain.Product
*/
@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    @Select("select * from product;")
    public List<Product> selectAll();

    public List<Double> getCount(Integer productid);

    public List<ProductMaterial> getAllProduct(Integer pageNo, Integer pageSize);

    public long getAllProductcount();

    public long getCountByName(String name);

    List<ProductMaterial> getAllProductByName(String name, Integer pageNo, Integer pageSize);

    long getCountById(int id);

    List<ProductMaterial> getAllProductById(int id, Integer pageNo, Integer pageSize);

    @Insert("insert into product (name , price , description,image,categoryid) values (#{name},#{price},#{description},#{image},#{categoryid})")
    void addProduct(ProductMaterial productMaterials);
    @Select("select productid from product where name=#{name}")
    public int getByName(String name);

    List<ProductMaterial> getAllOnlyProduct(Integer pageNo, Integer pageSize);

    List<ProductMaterial> getAllOnlyProductByName(String name, Integer pageNo, Integer pageSize);

    List<ProductMaterial> getAllOnlyProductById(int id, Integer pageNo, Integer pageSize);

    List<ProductMaterial> getAllOnlyProductByCategory(int category, Integer pageNo, Integer pageSize);

    long getCountByCategory(int category);
    @Update("update product set name=#{name},price=#{price},description=#{description},image=#{image},categoryid=#{categoryid} where productid=#{productid}")
    void setAll(Integer productid, String name, Double price, String description, String image, Integer categoryid);

    List<ProductMaterial> getAllOnlyProductNoPage();
}
